<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            返修确认记录
        </div>
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:60px;">
        <ul class="aui-list aui-form-list">
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">当前操作人:</div>
                    <input type="text" class="aui-input" id="empName" disabled style="width: 80%;" />
                    <i class="aui-btn aui-btn-info aui-input-addon aui-iconfont" onclick="takeQuitPostClick()">上岗</i>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">条码扫码区:</div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="请扫描条码" id="barcode" value="" onclick="getIdSelector();">
                    </div>
                </div>
            </li>
        </ul>
        <div class="aui-btn aui-btn-info aui-btn-block" onclick="doSave()">保存</div>

        <div style="background-color:white; height: 100%;width: 100%;margin-top:2%;margin-bottom:20%">
            <table class="table" style='width:100%;' id="table">
                <thead>
                    <tr
                        style="text-align: center;background-color: #DCE9F2;color: #467aa7;font-size: 12px;font-weight: bold;">
                        <td algin='center'>序号</td>
                        <td algin='center'>生产日期</td>
                        <td algin='center'>生产线</td>
                        <td algin='center'>总成码</td>
                        <td algin='center'>操作人</td>
                        <td algin='center'>操作时间</td>
                    </tr>
                </thead>
                <tbody id="tbodyHtml">
                </tbody>
            </table>
        </div>


    </div>
    
    <footer class="aui-bar aui-bar-tab" id="footer">
        <div class="aui-bar-tab-item" tapmode id="scan" onclick="doScan()">
            <i class="aui-iconfont aui-icon-scan aui-text-epblue" style="font-size: 1.8rem"></i>
        </div>
    </footer>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">

    var equipUniqueId = "";   //设备唯一号
    var workCenterCode = "";  //生产线编码
    var workCellCode = "";    //工位编码
    var opCode = "";          //工序编码
    var ruleCode = "";          //条码规则
    var scancodeWeb = "";
    var teamCode = "";        //班组编码
    var teamName = "";        //班组名称
    var shiftCode = "";       //班次编码
    var shiftName = "";       //班次名称
    var proddate = "";        //生产日期
    var pageParam = {};
    var barcode = "";//产品条码
    var mrlName = "";//物料名称
    var arrSave = [];
    var isCheckPersonnelSkill = "";//是否开启人员上岗技能校验


    // 获取光标所在组件的id
    function getIdSelector() {
        var e = event || window.event;
        var el = e.srcElement || e.target;
        idSelector = el.id;
        $("#" + el.id).select();
    }

    //初始化查询仓库下拉框
    apiready = function () {

        //获取设备唯一号
        equipUniqueId = localStorage.getItem('equipUniqueId');
        $("#barcode").focus();
        idSelector = "barcode";
        //1:查询产线工位信息
        searchWorkCenterData();
        doSearch()

    }

    function doSave() {
        var probarcode = $("#barcode").val();
        if (probarcode == "" || probarcode == null || probarcode == undefined) {
            api.toast({
                msg: '条码不能为空！',
                duration: 3000
            });
            return;
        }
        api.showProgress({
            title: '保存中...',
        });
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/saveProductFx";
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                opCode: opCode,
                probarcode: probarcode,
                stationCode: workCellCode,
                prodate: proddate,
                equipmentno: equipUniqueId,
                lineCode: workCenterCode,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {

                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == '0') {
                    $("#barcode").val("")
                    api.hideProgress();
                    doSearch()
                    api.toast({
                        msg: "保存成功",
                        duration: 3000
                    });
                } else {
                    api.hideProgress();
                    api.toast({
                        msg: myobj.msg,
                        duration: 3000
                    });
                }
            }
        });
    }

    //查询
    function doSearch() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/selectProductSG";
        var data = {
            values: {
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //返回成功
                if (myobj.code == "0") {
                    var list = eval(myobj.list);
                    var html = "";
                    for (var i = 0; i < list.length; i++) {
                        html += "<tr style='text-align: center;color: black;font-size: 10px;background-color: #F5F5F5;'>";
                        html += "<td name='seqno'>" + (i + 1) + "</td>";
                        html += "<td name='prodate'>" + list[i].prodate + "</td>";
                        html += "<td name='lineCode'>" + list[i].lineCode + "</td>";
                        html += "<td name='probarcode'>" + list[i].probarcode + "</td>";
                        html += "<td name='createId'>" + list[i].createId + "</td>";
                        html += "<td name='createDate'>" + list[i].createDate + "</td>";
                        html += "</tr>";
                    }
                    $api.html($api.byId("tbodyHtml"), html);

                    //失败
                } else if (myobj.code == "1") {
                    $("#barcode").val("")

                    //清空表格数据
                    $api.html($api.byId("tbodyHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }



    //查询数据
    function refresh() {

        //1:查询当前操作人员信息
        searchDutyPersonData();

        //查询过点
       // getPassPoint();
    }



    //上岗
    function takeQuitPostClick() {
        if (opCode == null || opCode == "" || opCode == undefined) {
            api.toast({
                msg: "唯一号【" + equipUniqueId + "】未配置工序信息",
                duration: 3000
            });
            return;
        }
        api.openWin({
            name: "productionSglg",
            url: 'productionSglg.html',
            pageParam: pageParam,
        });
    }
    //构造传参map
    function createPageParam() {
        pageParam = {
            workCenterCode: workCenterCode,
            workCellCode: workCellCode,
            opCode: opCode,
            ruleCode: ruleCode,
            teamCode: teamCode,
            teamName: teamName,
            shiftCode: shiftCode,
            shiftName: shiftName,
            proddate: proddate,
            rootName: "paScanProduSG",
            name: "paScanProduSG",
            sgFlag: '0',//上岗标识：0刷卡，1勾选
            isCheckPersonnelSkill: isCheckPersonnelSkill
        }
    }




    //查询产线工位信息
    function searchWorkCenterData() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getOpCodeByUniCode";
        var data = {
            values: {
                clientCode: equipUniqueId,
                un: un,
            }
        };

        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                if (myobj.code == 0) {

                    //标题
                    workCenterCode = myobj.workCenterCode;
                    workCellCode = myobj.workCellCode;
                    opCode = myobj.opCode;
                    ruleCode = myobj.ruleCode;
                    isCheckPersonnelSkill = myobj.isCheckPersonnelSkill;

                    if (opCode != null && opCode != "") {

                        //1:查询当前操作人员信息
                        searchDutyPersonData();

                    }

                } else {
                    api.toast({
                        msg: myobj.msg,
                        duration: 3000
                    });
                }
            } else {
                alert("网络连接超时!")
            }
        });
    }


    //查询人员信息
    function searchDutyPersonData() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getProductionAssemblyTake";
        var data = {
            values: {
                workCenterCode: workCenterCode,
                opCode: opCode,
                workCellCode:workCellCode,
                un: un,
            }
        };
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                console.log(myobj.code)

                if (myobj.code == 0) {
                    console.log(myobj.empName)
                    document.getElementById("empName").value = myobj.empName;
                    teamCode = myobj.teamCode;
                    teamName = myobj.teamName;
                    shiftCode = myobj.shiftCode;
                    shiftName = myobj.shiftName;
                    proddate = myobj.proddate;


                } else {
                    api.toast({
                        msg: myobj.msg,
                        duration: 3000
                    });

                    //清空人员信息
                    clear();
                }
                //查询过点
                // getPassPoint();
                //5:构造参数
                createPageParam();
            } else {
                alert("网络连接超时!")
            }
        });
    }

    //清空人员上岗信息
    function clear() {
        document.getElementById("empName").innerHTML = "";
        teamCode = "";
        teamName = "";
        shiftCode = "";
        shiftName = "";
        proddate = "";
    }
    //查找当前工序最后一个件信息
    function searchWorkLast() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getProductionAssemblyTake";
        var data = {
            values: {
                workCenterCode: workCenterCode,
                opCode: opCode,
                un: un,
            }
        };
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

    }



    //扫描之后条码解析
    function tmSplit(sm) {
        console.log("tmSplit:" + JSON.stringify(sm));
        var arr = sm.split(",");
        console.log("split:" + JSON.stringify(arr));
        if (arr.length == 1) {
            $("#boxnum").val(sm);
            doSearch();
        } else {
            //直接解析
            if (scanRule == "old") {

                //本地解析
                localAnalyze(sm);

            } else {

                //后台解析
                postAnalyze(sm);
            }
        }
    }

    //本地解析
    function localAnalyze(sm) {
        var arr = sm.split(",");
        if (arr[9] == null || arr[9] == undefined) {
            $("#boxnum").val("");
        } else {
            $("#boxnum").val(arr[9]);
        }
        doSearch();

    }

    //后台解析条码
    function postAnalyze(sm) {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/analysisBarCodeCommon";
        var data = {
            values: {
                tm: sm, //条码
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == '0') {

                    var map = myobj.data;
                    $("#boxnum").val(map["boxnum"]);
                    //自动保存
                    doSearch();
                } else if (myobj.code == '1') {

                    $("#boxnum").val("");
                    $("#boxnum").select();
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                alert(JSON.stringify(err));
            }
        });
    }

    //扫描
    function doScan() {
        var moduleScanner = api.require('moduleScanner');
        var params = {
            top: 150, //扫描窗口的上边距
            width: 250, //扫描窗口的宽
            height: 250, //扫描窗口的高
            useColor: false, //是否使用自己设定的颜色(startColor和endColor),
            //如果不使用设定的颜色就使用默认的那张网格图
            startColor: '#0F08C8FF', //渐变起始颜色
            endColor: '#7F08C8FF', //渐变结束颜色
            animTime: 2200, //扫描动画时间,单位为毫秒
        };
        moduleScanner.toScannerActivityForResult(params, function (ret, err) {
            //1：箱号
            if (idSelector == 'boxnum') {

                $("#boxnum").val(ret);

                //24：调入库位
            } else if (idSelector == 'barcode') {

                $("#barcode").val(ret);
                doSave()


            }
        });
    }

    $("#barcode").on('keypress', function (e) { //#keyword为input文本框
        var keycode = e.keyCode;
        var sm = $(this).val();
        if (keycode == '13') {

            $("#barcode").val(sm);
            doSave()

        }
    });

    //返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>